
package com.yuan.adapt;

import com.yuan.prefence.FileConstants;
import com.yuan.unit.FileUtils;

import org.json.JSONException;

import java.io.IOException;
import java.io.StreamCorruptedException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AdaptListUtils {
    private static List<Map<String, Object>> list = null;
    private volatile static AdaptListUtils sInstance;

    private AdaptListUtils()
    {
        list = new ArrayList<Map<String, Object>>();
    }

    public static AdaptListUtils getInstance() {
        if (sInstance == null) {
            synchronized (AdaptListUtils.class) {
                if (sInstance == null) {
                    sInstance = new AdaptListUtils();
                }
            }
        }
        return sInstance;
    }

    public List<Map<String, Object>> getMenuList()
    {
        list.clear();

        Map<String, Object> m = new HashMap<String, Object>();
        m.put("title", "显示地图");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "申请假期");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "查看考勤");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "查看审批");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "查看轨迹");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "密码修改");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "系统设置");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "分享");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "关于");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("title", "退出");
        list.add(m);

        return list;
    }

    @SuppressWarnings("unchecked")
    public List<Map<String, Object>> getSystemConfig() throws JSONException
    {
        list.clear();
        try {
            list = (List<Map<String, Object>>) FileUtils
                    .File2erializable(FileConstants.SERIALIZABLE_CONFIG);
        } catch (StreamCorruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getChinaCity()
    {
        list.clear();

        Map<String, Object> m = new HashMap<String, Object>();
        m.put("city", "全国");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("city", "北京");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("city", "上海");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("city", "广州");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("city", "青岛");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("city", "济南");
        list.add(m);

        m = new HashMap<String, Object>();
        m.put("city", "西安");
        list.add(m);

        return list;
    }

    public List<Map<String, Object>> getLeaveType()
    {
        list.clear();

        return list;
    }

    @SuppressWarnings("unchecked")
    public List<Map<String, Object>> getAllLeaveAccountList()
    {
        list.clear();
        try {
            list = (List<Map<String, Object>>) FileUtils
                    .File2erializable(FileConstants.SERIALIZABLE_请假申请记录);
        } catch (StreamCorruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return list;

    }

}
